package com.escool.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.escool.model.TbGrado;
@Repository
public class GradosDAOImpl implements GradosDAO {
	
	@Autowired
	SessionFactory sessionFactory;

	@Override
	public void addGrados(TbGrado grados) {
		this.sessionFactory.getCurrentSession().save(grados);

	}

	@Override
	public void updateGrados(TbGrado grados) {
		this.sessionFactory.getCurrentSession().update(grados);

	}

	@Override
	public List<TbGrado> listGrados() {
		
		return this.sessionFactory.getCurrentSession().createQuery("from TbGrado").list();
	}

	@Override
	public void deleteGrados(Integer id) {
		TbGrado grados = (TbGrado) this.sessionFactory.getCurrentSession().load(TbGrado.class, id);
		if(grados != null){
			this.sessionFactory.getCurrentSession().delete(grados);
		}

	}

	@Override
	public TbGrado findGrado(Integer id) {
		
		return (TbGrado) sessionFactory.getCurrentSession().get(TbGrado.class, id);
	}

}
